package com.bhsy.hellobootspring.servlet;

import com.bhsy.hellobootspring.Application;
import com.bhsy.hellobootspring.SpringContextUtil;
import com.bhsy.hellobootspring.controller.UserController;
import com.bhsy.hellobootspring.model.User;
import org.apache.catalina.core.ApplicationContext;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class UserAdd extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
      {
        doPost(req,resp);
      }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
      {
        UserController userController = (UserController)SpringContextUtil.getBean("w1");
        User user = new User("bhsy","123456");
        int a = userController.addUser(user);
        if(a == 1)
          {
            System.out.println(user);
          }
      }
}
